/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package se.bth.ke.firstfriend.model.dto;

import se.bth.ke.firstfriend.model.CheckPoint.State;
import se.bth.ke.firstfriend.model.Article;
import se.bth.ke.firstfriend.model.CheckPoint;
import se.bth.ke.firstfriend.model.CompletedCheckPoint;
import se.bth.ke.firstfriend.model.Todo;

/**
 *
 * @author nico
 */
public class TodoInfo {

    private final Article article;
    private final Todo todo;
    
    private CheckPoint checkPoint;

    public TodoInfo(Todo todo, Article article, CheckPoint checkPoint) {
        this.article = article;
        this.todo = todo;

        this.checkPoint = checkPoint;
    }

    /**
     * @return the article
     */
    public Article getArticle() {
        return article;
    }

    /**
     * @return the todo
     */
    public Todo getTodo() {
        return todo;
    }
    
    public boolean isDeleted() {
        return checkPoint.is(State.DELETED);
    }
    
    public boolean isInProgress() {
        return checkPoint.is(State.WORK_IN_PROGRESS);
    }

    public boolean isDone() {
        return checkPoint.is(State.DONE);
    }

    @Override
    public String toString() {
        return "se.bth.ke.firstfriend.model.dto.TodoInfo(" + article + ", " + todo + ", " + checkPoint + ")";
    }

    /**
     * Adds a new check point to the contained todo
     * and sets the check point as the current one
     * 
     * @param state to set on the todo
     */
    public void changeTodoStateTo(State state) {
        CheckPoint cp = (state == State.DONE ?
            new CompletedCheckPoint() :
            new CheckPoint(state));
        
        todo.addCheckPoint(cp);
        checkPoint = cp;
    }
}
